﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
<base href="<%=basePath%>">
	<meta charset="utf-8" />
		<title>江船公司管理</title>		
		
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
			<script type="text/javascript" src="static/js/jquery-1.7.2.js" />
			<script type="text/javascript" src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
			<link rel="stylesheet" href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
			
			
</head>
<body class="no-skin">
<div id="selForm"></div>
<div id="selForm1"></div>
<div id="selForm2"></div>
	</body>

<script type="text/javascript">
Ext.onReady(function(){
	var store = Ext.create('Ext.data.Store', {
		fields: ["BOAT_ID",
		 		"RIVER_BOAT_CODE",
				"RIVER_BOAT_NAME",
				"SETTLE_COMPANY",
				"SETTLE_DEPARTMENT_SEARCH_CODE",
				"ENABLE"],
		pageSize: 15,  //页容量5条数据
		//是否在服务端排序 （true的话，在客户端就不能排序）
		remoteSort: false,
		remoteFilter: true,
		proxy: {
			type: 'ajax',
			url: '<%=basePath%>riverboat/findRiverBoat',
			reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
				type: 'json', //返回数据类型为json格式
				root: 'result.list',  //数据
				totalProperty: 'result.total' //数据总条数
			}
		},
		sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad:{start:0,limit:15},
	});
	var tradeTypeStore = Ext.create('Ext.data.Store', {
		fields: ['id', 'name'],
		data : [
			{"id":"", "name":"请选择"},
			{"id":"1", "name":"是"},
			{"id":"0", "name":"否"}
		]
	});
	  var paging = new Ext.PagingToolbar(
				{
					store : store,
					pageSize:15,
					displayInfo : true,
					displayMsg : '<span style="color:blue;">第{0}条</span>至<span style="color:blue;">{1}条</span>，共<span style="color:blue;">{2}</span>条记录',
					emptyMsg : '无记录'
				});
	  var c1 = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				{id:"ID",xtype: 'textfield', name: 'ID',padding: '5px',fieldLabel: 'ID',hidden:true},
				{id:"startDate1",xtype: 'textfield', name: 'startDate1',columnWidth: 1/5,padding: '5px',fieldLabel: '江船代码'},
				{id:"startDate2",xtype: 'textfield', name: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '江船名称'},
				{id:"startDate3",xtype: 'textfield', name: 'startDate3', columnWidth:  1/5,padding: '5px', fieldLabel: '结算公司'},
				{id:"startDate4",xtype: 'combobox',  name: 'startDate4',value:'',editable: false,displayField: 'name', queryMode: 'local',store:tradeTypeStore,valueField: 'id', columnWidth:  1/5,padding: '5px', fieldLabel: '是否可用'},
				{id:"startDate5",xtype: 'textfield', name: 'startDate5', columnWidth:  1/5,padding: '5px', fieldLabel: '结算单位检索码'},
			]
		});
	  var bs2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 2/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "添加",handler: function(){
							var RIVER_BOAT_CODE = Ext.getCmp('startDate1').getValue();
				      		var RIVER_BOAT_NAME = Ext.getCmp('startDate2').getValue();
				      		var SETTLE_COMPANY = Ext.getCmp('startDate3').getValue();
				      		var ENABLE = Ext.getCmp('startDate4').getValue();
				      		var SETTLE_DEPARTMENT_SEARCH_CODE = Ext.getCmp('startDate5').getValue();

				      		//判断输入框是否为空
				      		//alert(RIVER_BOAT_CODE);
							var count = 0;
							if(RIVER_BOAT_CODE==null || RIVER_BOAT_CODE==""){
							    count++;
							    //Ext.getCmp("startDate1").setValue("江船代码不能为空");

							}
							if(RIVER_BOAT_NAME==null || RIVER_BOAT_NAME==""){
							    count++;
							    //Ext.getCmp("startDate2").setValue("江船名称不能为空")
							}
							if(SETTLE_COMPANY==null || SETTLE_COMPANY==""){
							    count++;
							    //Ext.getCmp("startDate3").setValue("结算公司不能为空");
							}
							if(ENABLE==null || ENABLE==""){
							    count++;
							    //Ext.getCmp("startDate5").setValue("结算单位检索码不能为空");
							}
							if(SETTLE_DEPARTMENT_SEARCH_CODE==null || SETTLE_DEPARTMENT_SEARCH_CODE==""){
							    count++;
							}


							if(count!=0){
								Ext.MessageBox.alert("提示","内容不能为空！！！");
							}else if(count==0){

                                var ID = "";
                                Ext.Ajax.request({
                                    url: '<%=basePath%>riverboat/saveRiverBoat',
                                    params:{ID:ID,RIVER_BOAT_CODE:RIVER_BOAT_CODE,RIVER_BOAT_NAME:RIVER_BOAT_NAME,ENABLE:ENABLE,SETTLE_COMPANY:SETTLE_COMPANY,SETTLE_DEPARTMENT_SEARCH_CODE:SETTLE_DEPARTMENT_SEARCH_CODE},
                                    method: 'POST',
                                    success: function () {
                                        Ext.MessageBox.alert("保存成功","保存成功");
//				                       var grid = Ext.getCmp('grid');
                                        Ext.getCmp("startDate1").setValue(null);
                                        Ext.getCmp("startDate2").setValue(null);
                                        Ext.getCmp("startDate3").setValue(null);
                                        Ext.getCmp("startDate4").setValue(null);
                                        Ext.getCmp("startDate5").setValue(null);

                                        grid.store.reload();
                                    },
                                });
                            }


				      	 } },
				      	{  style: {marginRight:'10px'},xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "修改",handler: function(){
				      		var records1 = grid.getSelectionModel().getSelection();
           	        	 if(records1.length==0){
           		       			Ext.Msg.alert("提示","请选择需要编辑的记录");return;
           		       		}
           		       		if(records1.length>1){
           		       			Ext.Msg.alert("提示","只能编辑一条记录");return;
           		       		}
           		   			  Ext.getCmp('ID').setValue(records1[0].data.BOAT_ID);
           		        		Ext.getCmp('startDate1').setValue(records1[0].data.RIVER_BOAT_CODE);
           		        		Ext.getCmp('startDate2').setValue(records1[0].data.RIVER_BOAT_NAME);
           		        		Ext.getCmp('startDate3').setValue(records1[0].data.SETTLE_COMPANY);
           		        		if(records1[0].data.ENABLE==1){
           		        			Ext.getCmp('startDate4').setValue("是");
           		        		}else{
           		        			Ext.getCmp('startDate4').setValue("否");
           		        		}
           		        		
           		        		Ext.getCmp('startDate5').setValue(records1[0].data.SETTLE_DEPARTMENT_SEARCH_CODE);


      							
      				      	 } },	
      				      	 { style: {marginRight:'10px'},xtype: "button", minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "保存修改信息",handler: function(){
      				      		var RIVER_BOAT_CODE = Ext.getCmp('startDate1').getValue();
    				      		var RIVER_BOAT_NAME = Ext.getCmp('startDate2').getValue();
    				      		var SETTLE_COMPANY = Ext.getCmp('startDate3').getValue();
    				      		var ENABLE = Ext.getCmp('startDate4').getValue();
    				      		var SETTLE_DEPARTMENT_SEARCH_CODE = Ext.getCmp('startDate5').getValue();
    		

    				      		var BOAT_ID = Ext.getCmp('ID').getValue();
    				      		 Ext.Ajax.request({
    				       			 url: '<%=basePath%>riverboat/saveRiverBoat',
    				        			 params:{BOAT_ID:BOAT_ID,RIVER_BOAT_CODE:RIVER_BOAT_CODE,RIVER_BOAT_NAME:RIVER_BOAT_NAME,ENABLE:ENABLE,SETTLE_COMPANY:SETTLE_COMPANY,SETTLE_DEPARTMENT_SEARCH_CODE:SETTLE_DEPARTMENT_SEARCH_CODE},
    				        			 method: 'POST',
    				        			success: function () {
    				                       Ext.MessageBox.alert("保存成功","保存成功");
//    				                       var grid = Ext.getCmp('grid');
    										Ext.getCmp("startDate1").setValue(null); 
    										Ext.getCmp("startDate2").setValue(null); 
    										Ext.getCmp("startDate3").setValue(null); 
    										Ext.getCmp("startDate4").setValue(null); 
    										Ext.getCmp("startDate5").setValue(null); 
    										
    				   					 grid.store.reload();
    				                   },
    				        		 });

     	      							
     	      				      	 } }],},
                      					
                   				
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
	  var c2 = Ext.create('Ext.container.Container', {
			layout: 'column',
			defaults: { labelAlign: 'left', labelWidth: 60 },
			items: [
				
{id:"startDate6",xtype: 'textfield', name: 'startDate6',columnWidth: 1/5,padding: '5px',fieldLabel: '江船代码'},
{id:"startDate7",xtype: 'textfield', name: 'startDate7', columnWidth:  1/5,padding: '5px', fieldLabel: '江船名称'},
{id:"startDate8",xtype: 'textfield', name: 'startDate8', columnWidth:  1/5,padding: '5px', fieldLabel: '结算公司'},
{id:"startDate9",xtype: 'textfield', name: 'startDate9', columnWidth:  1/5,padding: '5px', fieldLabel: '结算单位检索码'},

			]
		});
	  var bs = Ext.create('Ext.container.Container', {
			layout: 'column',
			items: [
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
				{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 1/5,  padding: '10px',  items: [
					{ style: {marginRight:'10px'}, xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "查询",handler: function(){
			      		 var RIVER_BOAT_CODE = Ext.getCmp('startDate6').getValue();
				      		var RIVER_BOAT_NAME = Ext.getCmp('startDate7').getValue();
				      		var SETTLE_COMPANY = Ext.getCmp('startDate8').getValue();
				      		var SETTLE_DEPARTMENT_SEARCH_CODE = Ext.getCmp('startDate9').getValue();
				      		
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store,options) {  
				            var new_params = {  
				            		RIVER_BOAT_CODE : RIVER_BOAT_CODE, RIVER_BOAT_NAME:RIVER_BOAT_NAME,SETTLE_COMPANY:SETTLE_COMPANY,SETTLE_DEPARTMENT_SEARCH_CODE:SETTLE_DEPARTMENT_SEARCH_CODE
				            };  
					//这里apply一下实现新的proxy  
				            Ext.apply(store.proxy.extraParams,new_params);  
				        });  
					//对store重新载入  
				        store.load();  


							
				      	 } },
				],},
				{layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
			]
		});
		var deleteInfo =new Ext.Button({
			text: '删除',
			handler:function(){
	     		var records = grid.getSelectionModel().getSelection();
	       			if(records.length==0){
	       				Ext.Msg.alert("提示","请选中需要删除的实体记录");return;
	       			}
	       			var arr = [];
	       			Ext.each(records,function(item){
	       				obj = {
	       						id:item.data.BOAT_ID
	       				};
	       				arr.push(obj);
	       			});
	       			var array = JSON.stringify(arr);
	       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
		       				
		       					Ext.Ajax.request({
		       						url:'<%=basePath%>riverboat/deleteInfo',
		       						params:{
		       							array:array
		       						},
		       						timeout:5000,
		       						success:function(response){
		       							store.load();
		       							Ext.Msg.alert("成功","删除成功!");
		       						},
		       						failure:function(response){
		       							Ext.Msg.alert("错误","请求异常!");
		       						}
		       					});
		       				
		       			});
	     	}
		});
		var grid = Ext.create('Ext.grid.Panel', {
			title:'江船公司管理',
			store: store,
			id:'grid',
			renderTo: "selForm2",
			height: 400,
			stripeRows:true,
			columnLines: true,
			bbar:paging,
			tbar: [deleteInfo],
			selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"single", allowDeselect: true, showHeaderCheckbox:false}),
			columns: [
				{text: 'BOAT_ID', dataIndex: 'BOAT_ID',hidden:true},
				{text: '江船代码', dataIndex: 'RIVER_BOAT_CODE'},
				{text: '江船名称', dataIndex: 'RIVER_BOAT_NAME'},
				{text: '结算公司', dataIndex: 'SETTLE_COMPANY'},
				{text: '结算公司检索码', dataIndex: 'SETTLE_DEPARTMENT_SEARCH_CODE'},
				{text: '是否可用', dataIndex: 'ENABLE',},
				
			],
		});
		var selForm = Ext.create('Ext.form.Panel', {
			
			name: 'selForm',
			renderTo: "selForm",
			width:'100%',
			height:130,
//			collapsed :true,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c1,bs2]
		});
		var selForm = Ext.create('Ext.form.Panel', {
			
			name: 'selForm',
			renderTo: "selForm1",
			width:'100%',
			height:130,
//			collapsed :true,
//			collapsible:true,
			bodyStyle: {
				padding: '5px',
				border: 1
			},
			fieldDefaults: {
				labelAlign: 'left'
			},
			items: [c2,bs]
		});
});


</script>
</html>
